/*
 * JoinRingCommand.h
 *
 *  Created on: Dec 21, 2009
 *      Author: kevin
 */

#ifndef JOINRINGCOMMAND_H_
#define JOINRINGCOMMAND_H_

#include "command/command.h"
using Commands::Command;
using Commands::CommandCreator;
using Commands::NotImplemented;

#include "node/node.h"

#include <string>
using std::string;

#include <Poco/Types.h>
using Poco::UInt16;

namespace Commands
{

	class JoinRingCommand: public Commands::Command
	{
		public:
			JoinRingCommand(string ringname, UInt16 port, NodeData* data = 0);
			virtual ~JoinRingCommand();

			/**
			 * Executes the command
			 */
			void execute();

			/**
			 * Returns the name by which the command is registered with a CommandFactory
			 * @return commandname
			 */
			string name();

			/**
			 * Undoes this command, if implemented. If not implemented, throws an NotImplemented excpetion.
			 */
			void undo();

			/**
			 * Return a string with which this command can be remade if it were fed into a CommandFactory
			 * @return representational string
			 */
			string repr();

			/**
			 * Return the creator to make this command given the representational string
			 * @return a CommandCreator for this Command
			 */
			CommandCreator creator();

			/**
			 * Return the name of the ring to join
			 * @return ringname
			 */
			string ringName();

		private:
			static Command* makeCommand(string r, void* s);
			static const string NAME;

			string _ringname;
			UInt16 _port;
			NodeData* _nodedata;
	};

}

#endif /* JOINRINGCOMMAND_H_ */
